package com.heima.article.controller;

import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.article.service.IApArticleService;
import com.heima.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private IApArticleService apArticleService;


    //保存文章
    @PostMapping
    public ResponseResult<Long> saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    //首页加载文章
    @PostMapping(value = "/load", name = "首页加载文章")
    public ResponseResult loadArticle(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadArticle(dto, 1);//发布时间大于maxTime
    }

    //首页加载文章-更新
    @PostMapping(value = "/loadnew", name = "首页加载文章-更新")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadArticle(dto, 2); //发布时间大于maxTime
    }

    //首页加载文章-更多
    @PostMapping(value = "/loadmore", name = "首页加载文章-更多")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadArticle(dto, 3); //发布时间小于minTime
    }

    //文章详情
    @PostMapping("/load_article_info")
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticleInfo(dto);
    }
}